<template>
  <div style="padding: 15px;">
    <div style="margin-bottom: 15px;">
      <Input style="width: 200px;" placeholder="请输入学生姓名"/>
      <Input style="width: 200px;" placeholder="请输入学生账号"/>
      <Select v-model="areaModel" style="width:200px" placeholder="请选择机构省份">
        <Option v-for="item in cityList" :value="item.value" :key="item.value">{{ item.label }}</Option>
      </Select>
      <Button @click="searchStudent" type="success">搜索</Button>
      <Button @click="batchAddStudent" type="primary" style="float: right;margin-left: 10px;">批量添加</Button>
      <Button @click="addStudent" type="primary" style="float: right;">添加学生</Button>
    </div>
    <Table border ref="selection" :columns="columns" :data="tableData"></Table>
    <Page :total="100" show-sizer style="margin-top: 15px;" />
    <Modal v-model="orgStudentModal" :title="modalTitle" @on-ok="ok" @on-cancel="cancel">
      <Form :model="orgStudentForm" :label-width="80">
        <FormItem label="学生姓名">
          <Input v-model="orgStudentForm.name" placeholder="请输入学生姓名"/>
        </FormItem>
        <FormItem label="账户名">
          <Input v-model="orgStudentForm.userName" placeholder="请输入学生账户名"/>
        </FormItem>
        <FormItem label="密码">
          <Input v-model="orgStudentForm.password" placeholder="请输入学生登录密码" type="password"/>
        </FormItem>
        <FormItem label="再次输入">
          <Input v-model="orgStudentForm.retypePassword" placeholder="请再次输入学生登录密码" type="password"/>
        </FormItem>
        <FormItem label="联系电话">
          <Input v-model="orgStudentForm.phone" placeholder="请输入联系电话"/>
        </FormItem>
        <FormItem label="所属机构">
          <Select v-model="orgStudentForm.orgBelong">
            <Option value="item.userName">杭州钱塘外国语学校</Option>
            <Option value="item.userName">上海西南位育国际学校</Option>
          </Select>
        </FormItem>
        <FormItem label="状态">
          <i-switch size="large">
            <span slot="open">启用</span>
            <span slot="close">禁用</span>
          </i-switch>
        </FormItem>
      </Form>
    </Modal>
    <Modal v-model="orgBatchAddStudentModal" :title="modalTitle" @on-ok="ok" @on-cancel="cancel">
      <Alert show-icon>
        下载导入模板
        <Icon type="ios-bulb-outline" slot="icon"></Icon>
        <template slot="desc">下载学生批量导入模板请&nbsp;&nbsp;<Button type="primary">点击这里</Button>&nbsp;&nbsp;下载，下载后请严格按照要求添加学生信息，否则将会导入失败。</template>
      </Alert>
      <Form :model="orgStudentForm" :label-width="80">
        <FormItem label="选择文件">
          <Upload action="//jsonplaceholder.typicode.com/posts/">
            <Button icon="ios-cloud-upload-outline">上传文件</Button>
          </Upload>
        </FormItem>
      </Form>
    </Modal>
  </div>
</template>

<script>
export default {
  name: 'index',
  data () {
    return {
      orgStudentForm: {},
      orgAdmin: '',
      orgAdminList: [
        {
          userName: 'zhumo',
          realName: '朱墨'
        },
        {
          userName: 'caimingxu',
          realName: '蔡明旭'
        }
      ],
      columns: [
        {
          type: 'selection',
          width: 60,
          align: 'center'
        },
        {
          title: '学生姓名',
          key: 'name',
          align: 'center',
          width: 100
        },
        {
          title: '账户名',
          key: 'userName',
          align: 'center',
          width: 100
        },
        {
          title: '所属机构',
          key: 'orgBelong',
          align: 'center'
        },
        {
          title: '联系电话',
          key: 'phone',
          align: 'center',
          width: 120
        },
        {
          title: '已购课程数',
          key: 'boughtClasses',
          align: 'center'
        },
        {
          title: '学习节次',
          key: 'learntChapter',
          align: 'center'
        },
        {
          title: '消费金额',
          key: 'consume',
          align: 'center'
        },
        {
          title: '注册时间',
          key: 'createTime',
          align: 'center',
          width: 150
        },
        {
          title: '状态',
          key: 'status',
          width: 120,
          align: 'center',
          render: (h, params) => {
            const row = params.row
            const color = row.status === '1' ? 'primary' : row.status === '0' ? 'error' : ''
            const text = row.status === '1' ? '正常' : row.status === '0' ? '禁用' : ''
            return h('Tag', {
              props: {
                type: 'dot',
                color: color
              }
            }, text)
          }
        },
        {
          title: '操作',
          key: 'action',
          width: 150,
          align: 'center',
          render: (h, params) => {
            return h('div', [
              h('Button', {
                props: {
                  type: 'primary',
                  size: 'small'
                },
                style: {
                  marginRight: '5px'
                },
                on: {
                  click: () => {
                    this.show(params.index)
                  }
                }
              }, '编辑'),
              h('Button', {
                props: {
                  type: 'error',
                  size: 'small'
                },
                on: {
                  click: () => {
                    this.remove(params.index)
                  }
                }
              }, '删除')
            ])
          }
        }
      ],
      tableData: [
        {
          name: '朱棣',
          orgBelong: '上海西南位育国际学校',
          userName: 'zhudi',
          phone: '13578869443',
          boughtClasses: '1',
          learntChapter: '2',
          consume: '130.00',
          createTime: '2018-11-15 12:10:11',
          updateTime: '2018-11-15 12:10:11',
          operator: 'admin',
          status: '1'
        },
        {
          name: '朱见深',
          orgBelong: '上海西南位育国际学校',
          userName: 'zhujian',
          phone: '13102189443',
          boughtClasses: '1',
          learntChapter: '2',
          consume: '130.00',
          createTime: '2018-11-15 12:10:11',
          updateTime: '2018-11-15 12:10:11',
          operator: 'admin',
          status: '0'
        }
      ],
      cityList: [
        {
          value: 'Zhe Jiang',
          label: '浙江省'
        },
        {
          value: 'An Hui',
          label: '安徽省'
        },
        {
          value: 'Shanghai',
          label: '上海市'
        },
        {
          value: 'Beijing',
          label: '北京市'
        },
        {
          value: 'He Bei',
          label: '河北省'
        },
        {
          value: 'Jiang Su',
          label: '江苏省'
        }
      ],
      areaModel: '',
      orgStudentModal: false,
      modalTitle: '',
      orgBatchAddStudentModal: false
    }
  },
  methods: {
    addStudent () {
      this.orgStudentModal = true
      this.modalTitle = '添加学生'
    },
    searchStudent () {
    },
    batchAddStudent () {
      this.orgBatchAddStudentModal = true
      this.modalTitle = '批量添加学生'
    }
  }
}
</script>

<style scoped>

</style>
